﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace YArchitech.Plumbing
{
	public partial class FormSystemClass : System.Windows.Forms.Form
	{
		public FormSystemClass(TextBox txtBox)
		{
			this.txtBox = txtBox;
			this.InitializeComponent();
			base.CenterToScreen();
		}

		private void FormSystemClass_Load(object sender, EventArgs e)
		{
			foreach (string item in Filter.listPipeTypeName)
			{
				this.listBox1.Items.Add(item);
			}
			foreach (string item2 in Filter.listMechanicalTypeName)
			{
				this.listBox1.Items.Add(item2);
			}
		}

		private bool judgeListBoxHave(ListBox lb1, ListBox lb2)
		{
			bool result = true;
			if (lb2.Items.Count > 0 && lb1.SelectedItem != null)
			{
				for (int i = 0; i < lb2.Items.Count; i++)
				{
					if (lb1.SelectedItem == lb2.Items[i])
					{
						result = false;
					}
				}
			}
			return result;
		}

		private void buttonToRight_Click(object sender, EventArgs e)
		{
			if (this.listBox1.SelectedItem != null && this.judgeListBoxHave(this.listBox1, this.listBox2))
			{
				this.listBox2.Items.Add(this.listBox1.SelectedItem);
				this.listBox1.Items.RemoveAt(this.listBox1.SelectedIndex);
			}
		}

		private void buttonToLeft_Click(object sender, EventArgs e)
		{
			if (this.listBox2.SelectedItem != null && this.judgeListBoxHave(this.listBox2, this.listBox1))
			{
				this.listBox1.Items.Add(this.listBox2.SelectedItem);
				this.listBox2.Items.RemoveAt(this.listBox2.SelectedIndex);
			}
		}

		private void buttonOK_Click(object sender, EventArgs e)
		{
			if (this.listBox2.Items.Count > 0)
			{
				string text = "";
				for (int i = 0; i < this.listBox2.Items.Count; i++)
				{
					text = text + this.listBox2.Items[i].ToString() + ",";
				}
				this.txtBox.Text = text;
				base.Close();
				return;
			}
			MessageBox.Show("请选择至少一个系统类型");
		}

		private void buttonESC_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private TextBox txtBox;
	}
}
